﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace PRO_DOCS.DocumentManagementSystem.ADMIN.WIN.Configurations.Departments
{
    public class ExportingXMLFiles
    {
        public void CREATE_DOCUMENT_XML_FILE(
            DAL.Database.ARCHIVE_DEPARTMENT_FILE aRCHIVE_DEPARTMENT_FILE,
            DAL.Database.ARCHIVE_DEPARTMENT_FILE_HISTORY aRCHIVE_DEPARTMENT_FILE_HISTORY,
            string fILE_EXPORTING_PATH,
            string xML_EXPORTING_PATH,
            PRO_DOCS.DAL.Database.PRO_DOCSDatabaseDataContext PRO_DOCSDatabaseDataContext)
        {
            #region 1. XML declaration section
            XmlDocument _xmlDoc = new XmlDocument();
            //1. Create the xml file header (XML declaration section)
            XmlNode _xmlNode = _xmlDoc.CreateNode(XmlNodeType.XmlDeclaration, String.Empty, "");
            _xmlDoc.AppendChild(_xmlNode);
            #endregion

            #region 2. Add the root element
            //2. Add the root element
            XmlElement _xmlElement = _xmlDoc.CreateElement(String.Empty, "DEPARTMENT_FILE", String.Empty);
            XmlText _xmlText = _xmlDoc.CreateTextNode(string.Empty);
            _xmlElement.AppendChild(_xmlText);
            _xmlDoc.AppendChild(_xmlElement);
            #endregion

            #region 3. ADD the file details
            XmlElement xmlSubElement = null;
            XmlText xmlSubNoodText = null;
            //barcode
            XmlElement fILE_DETAILS_xmlElement = _xmlDoc.CreateElement(String.Empty, "FILE_DETAILS", String.Empty);
            XmlText subroot_xmlText = _xmlDoc.CreateTextNode(string.Empty);
            fILE_DETAILS_xmlElement.AppendChild(subroot_xmlText);
            _xmlElement.AppendChild(fILE_DETAILS_xmlElement);
            //employee_id
            xmlSubElement = _xmlDoc.CreateElement(String.Empty, "FILE_CREATION_DATE", String.Empty);
            xmlSubNoodText = _xmlDoc.CreateTextNode(aRCHIVE_DEPARTMENT_FILE.ARCHIVE_DEPARTMENT_FILE_CREATION_DATE.Value.ToString());
            xmlSubElement.AppendChild(xmlSubNoodText);
            fILE_DETAILS_xmlElement.AppendChild(xmlSubElement);
            //employee_first_name
            xmlSubElement = _xmlDoc.CreateElement(String.Empty, "FILE_CREATION_USER", String.Empty);
            xmlSubNoodText = _xmlDoc.CreateTextNode(aRCHIVE_DEPARTMENT_FILE.LOGIN_USER.EMPLOYEE_FULL_NAME);
            xmlSubElement.AppendChild(xmlSubNoodText);
            fILE_DETAILS_xmlElement.AppendChild(xmlSubElement);
            //employee_second_name
            xmlSubElement = _xmlDoc.CreateElement(String.Empty, "FILE_DISPLAY_NAME", String.Empty);
            xmlSubNoodText = _xmlDoc.CreateTextNode(aRCHIVE_DEPARTMENT_FILE.ARCHIVE_DEPARTMENT_FILE_DISPLAY_NAME);
            xmlSubElement.AppendChild(xmlSubNoodText);
            fILE_DETAILS_xmlElement.AppendChild(xmlSubElement);
            //employee_last_name
            xmlSubElement = _xmlDoc.CreateElement(String.Empty, "GENERATED_BARCODE_VALUE", String.Empty);
            xmlSubNoodText = _xmlDoc.CreateTextNode(aRCHIVE_DEPARTMENT_FILE.ARCHIVE_DEPARTMENT_FILE_GENERATED_BARCODE_VALUE);
            xmlSubElement.AppendChild(xmlSubNoodText);
            fILE_DETAILS_xmlElement.AppendChild(xmlSubElement);
            //department_name
            xmlSubElement = _xmlDoc.CreateElement(String.Empty, "FILE_DISPLAY_NOTES", String.Empty);
            xmlSubNoodText = _xmlDoc.CreateTextNode(aRCHIVE_DEPARTMENT_FILE.ARCHIVE_DEPARTMENT_FILE_DISPLAY_NOTES);
            xmlSubElement.AppendChild(xmlSubNoodText);
            fILE_DETAILS_xmlElement.AppendChild(xmlSubElement);
            //department_name
            xmlSubElement = _xmlDoc.CreateElement(String.Empty, "FILE_EXPORTING_PATH", String.Empty);
            xmlSubNoodText = _xmlDoc.CreateTextNode(fILE_EXPORTING_PATH);
            xmlSubElement.AppendChild(xmlSubNoodText);
            fILE_DETAILS_xmlElement.AppendChild(xmlSubElement);
            //employee_third_name
            xmlSubElement = _xmlDoc.CreateElement(String.Empty, "FILE_DOCUMENT_TYPE", String.Empty);
            string aRCHIVE_DOCUMENT_TYPE = (aRCHIVE_DEPARTMENT_FILE.ARCHIVE_DOCUMENT_TYPE != null) ? aRCHIVE_DEPARTMENT_FILE.ARCHIVE_DOCUMENT_TYPE.ARCHIVE_DOCUMENT_TYPE_NAME : "<N/A>";
            xmlSubNoodText = _xmlDoc.CreateTextNode(aRCHIVE_DOCUMENT_TYPE);
            xmlSubElement.AppendChild(xmlSubNoodText);
            fILE_DETAILS_xmlElement.AppendChild(xmlSubElement);
            if (aRCHIVE_DEPARTMENT_FILE.ARCHIVE_DOCUMENT_TYPE != null)
            {
                //Documents
                XmlElement fILE_DOC_TYPE_xmlElement = _xmlDoc.CreateElement(String.Empty, "DOCUMENT_INDECIES", String.Empty);
                XmlText fILE_DOC_TYPE_xmlText = _xmlDoc.CreateTextNode(string.Empty);
                fILE_DOC_TYPE_xmlElement.AppendChild(fILE_DOC_TYPE_xmlText);
                _xmlElement.AppendChild(fILE_DOC_TYPE_xmlElement);

                DAL.Database.ARCHIVE_DOCUMENT_TYPE CURRENT_SELECTED_ARCHIVE_DOCUMENT_TYPE = (from indecies in PRO_DOCSDatabaseDataContext.ARCHIVE_DOCUMENT_TYPEs
                                                                                             where indecies.ARCHIVE_DOCUMENT_TYPE_ID.Equals(aRCHIVE_DEPARTMENT_FILE.ARCHIVE_DEPARTMENT_FILE_DOCUMENT_TYPE_ID.Value)
                                                                                             select indecies
                                                                                             ).FirstOrDefault();

                List<DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX> aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDECIES = CURRENT_SELECTED_ARCHIVE_DOCUMENT_TYPE.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEXes.OrderBy(k => k.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value).ToList();


                XmlElement xmlDocTypeElement = null;
                XmlText xmlDocTypeNoodText = null;
                //barcode
                for (int i = 0; i < aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDECIES.Count; i++)
                {
                    xmlDocTypeElement = _xmlDoc.CreateElement(String.Empty, "INDEX", String.Empty);
                    xmlDocTypeElement.SetAttribute("INDEX_NAME", aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDECIES[i].ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_NAME);
                    //set the document Index value
                    DAL.Database.ARCHIVE_DEPARTMENT_FILE_HISTORY_INDEXES_VALUE hISTORY_VALUE = (from hValue in PRO_DOCSDatabaseDataContext.ARCHIVE_DEPARTMENT_FILE_HISTORY_INDEXES_VALUEs
                                                                                                where
                                                                                                (
                                                                                                    hValue.ARCHIVE_DEPARTMENT_FILE_HISTORY_ID.Equals(aRCHIVE_DEPARTMENT_FILE_HISTORY.ARCHIVE_DEPARTMENT_FILE_HISTORY_ID) &&
                                                                                                    hValue.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.Equals(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDECIES[i].ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID)
                                                                                                )
                                                                                                select hValue).FirstOrDefault();

                    string fILE_INDEX_VALUE = (hISTORY_VALUE != null) ? hISTORY_VALUE.ARCHIVE_DEPARTMENT_FILE_HISTORY_INDEX_VALUE : string.Empty;
                    xmlDocTypeNoodText = _xmlDoc.CreateTextNode(fILE_INDEX_VALUE);
                    xmlDocTypeElement.AppendChild(xmlDocTypeNoodText);
                    fILE_DOC_TYPE_xmlElement.AppendChild(xmlDocTypeElement);
                }
            }

            #endregion
            #region 32 - Corporate files (DONE)

            //string fileName = string.Empty;

            ////Add the root subEmelemnts
            //string employee_id = string.Empty;
            //for (int i = 0; i < employeeBatches.Count; i++)
            //{

            //    DAL.GarafatDatabase.INFC_BATCH employeeBatch = employeeBatches[i];

            //    if (employeeBatch.INFC_BATCH_INDEX != null)
            //    {

            //        List<DAL.GarafatDatabase.INFC_PAGE> batchImages = employeeBatch.INFC_PAGEs.OrderBy(k => k.PAGE_FLD01_VAL).ToList();


            //        employee_id = employeeBatch.INFC_BATCH_INDEX.INFC_BATCH_INDEX_BATCH_NUMBER;
            //        string employee_first_name = employeeBatch.INFC_BATCH_INDEX.INFC_BATCH_INDEX_BATCH_NAME;

            //        List<string> empIndecies = employeeBatch.INFC_BATCH_INDEX.INFC_BATCH_INDEX_BATCH_TYPE.Split('|').ToList();
            //        string employee_second_name = string.Empty;
            //        string employee_third_name = string.Empty;
            //        string employee_last_name = string.Empty;
            //        string department_name = string.Empty;
            //        if (empIndecies.Count > 0)
            //        {
            //            try
            //            {
            //                employee_second_name = (empIndecies[0] != null) ? empIndecies[0] : string.Empty;
            //                employee_third_name = (empIndecies[1] != null) ? empIndecies[1] : string.Empty;
            //                employee_last_name = string.Empty;
            //                department_name = (empIndecies[2] != null) ? empIndecies[2] : string.Empty;
            //            }
            //            catch { }
            //        }
            //        string barcode_value = string.Empty;
            //        string main_category_code = string.Empty;
            //        string main_category_name = string.Empty;
            //        string sub_category_code = string.Empty;
            //        string sub_category_name = string.Empty;
            //        string document_type_code = string.Empty;
            //        string document_type_name = string.Empty;
            //        string number_of_pages = employeeBatch.INFC_PAGEs.Count.ToString();
            //        string absolute_folder_path = string.Empty;
            //        string file_name = string.Format("EMP.ID.{0}.pdf", employee_id);




            //        //hold the file name that are stabled
            //        /*
            //         * key      :   stable name.
            //         * value    :   images list
            //         */
            //        Dictionary<string, List<DAL.GarafatDatabase.INFC_PAGE>> generatedStabledImages = new Dictionary<string, List<DAL.GarafatDatabase.INFC_PAGE>>();

            //        //hold the separated file images that are notr stabled
            //        Dictionary<string, List<string>> generatedImages = new Dictionary<string, List<string>>();

            //        for (int bi = 0; bi < batchImages.Count; bi++)
            //        {

            //            List<string> fileImageFullPathes = new List<string>();
            //            //get the added document types

            //            //get the current main category name for separation
            //            main_category_name = (string.IsNullOrEmpty(batchImages[bi].PAGE_FLD01_VAL)) ? string.Empty : batchImages[bi].PAGE_FLD01_VAL;

            //            sub_category_name = (string.IsNullOrEmpty(batchImages[bi].PAGE_FLD05_VAL)) ? string.Empty : batchImages[bi].PAGE_FLD05_VAL;

            //            document_type_name = (string.IsNullOrEmpty(batchImages[bi].PAGE_FLD06_VAL)) ? string.Empty : batchImages[bi].PAGE_FLD06_VAL;

            //            string stableName = (string.IsNullOrEmpty(batchImages[bi].PAGE_FLD04_VAL)) ? string.Empty : batchImages[bi].PAGE_FLD04_VAL;
            //            if (!string.IsNullOrEmpty(stableName))
            //            {
            //                if (!generatedStabledImages.ContainsKey(stableName))
            //                {
            //                    generatedStabledImages.Add(stableName, new List<DAL.GarafatDatabase.INFC_PAGE>());
            //                }

            //                List<DAL.GarafatDatabase.INFC_PAGE> stableImages = generatedStabledImages[stableName];
            //                stableImages.Add(batchImages[bi]);
            //                generatedStabledImages[stableName] = stableImages;

            //            }
            //            else
            //            {
            //                #region single separated document types

            //                string generatedImagesKey = string.Format("{0}*{1}*{2}", main_category_name, sub_category_name, document_type_name);

            //                if (!generatedImages.ContainsKey(generatedImagesKey))
            //                {
            //                    generatedImages.Add(generatedImagesKey, new List<string>());
            //                }



            //                fileImageFullPathes = generatedImages[generatedImagesKey];

            //                //create the file Folders structure
            //                /*
            //                 |<employee_id>
            //                        |
            //                        |<main_category_name>
            //                                |
            //                                |<sub_category_name>
            //                                        |
            //                                        |<document_type_name>
            //                                                |
            //                                                |<file_name.pdf> (single Or multiple)
            //                 */

            //                absolute_folder_path = Path.Combine("W" + weekNumber.ToString(), employee_id, main_category_name.Split('.').ToList()[0], sub_category_name.Split('.').ToList()[0], document_type_name.Split('.').ToList()[0]);

            //                string full_folder_path = Path.Combine(currentExportingFolder, absolute_folder_path);

            //                DirectoryInfo dirFull_folder_path = new DirectoryInfo(full_folder_path);
            //                dirFull_folder_path.Create();

            //                int newFileCount = 0;

            //                try { newFileCount = (createdImagesNames[full_folder_path].Count + 1); }
            //                catch
            //                {
            //                    newFileCount = 1;
            //                }//---------->//dirFull_folder_path.GetFiles("*.tiff").Count() + 1;

            //                #region add temp names
            //                //add temp names

            //                if (!createdImagesNames.ContainsKey(full_folder_path))
            //                {
            //                    createdImagesNames.Add(full_folder_path, new List<string>());
            //                }

            //                List<string> tempImagesNames = createdImagesNames[full_folder_path];
            //                tempImagesNames.Add((newFileCount).ToString());
            //                createdImagesNames[full_folder_path] = tempImagesNames;
            //                #endregion

            //                //int newFileCount = dirFull_folder_path.GetFiles("*.txt").Count() + 1;//For the text test

            //                //string newTiffFileName = string.Format("{0}.txt", newFileCount.ToString("000000"));//For the text test
            //                string newTiffFileName = string.Format("{0}.tiff", newFileCount.ToString("000000"));//For the tiff test
            //                file_name = string.Format("{0}.pdf_1", newFileCount.ToString("000000"));

            //                //copy the tiff file to be then converted to pdf
            //                //new FileInfo(Path.Combine(full_folder_path, newTiffFileName)).Create();//For the text test
            //                /*For the tiff test*/
            //                string toTiffFile = Path.Combine(full_folder_path, string.Format("{0}.tiff", file_name.Replace(".pdf_1", string.Empty)));
            //                if (exportImages)
            //                {
            //                    FileInfo tiffFile = new FileInfo(Path.Combine(batchImages[bi].PAGE_PATH, batchImages[bi].PAGE_NAME));
            //                    List<FileInfo> tiffFiles = new List<FileInfo>();
            //                    tiffFiles.Add(tiffFile);
            //                    GENERATE_MULTITIFF_FILE(tiffFiles, toTiffFile);
            //                    //tiffFile.CopyTo(toTiffFile, true);
            //                    //Image clipboardImage = Image.FromFile(toTiffFile);
            //                    //if (clipboardImage.Width < 1000)
            //                    //{
            //                    //    ScaleImage(clipboardImage, 1776, 2490);
            //                    //}
            //                }


            //                //GENERATE_MULTITIFF_FILE(new List<DAL.GarafatDatabase.INFC_PAGE>() {batchImages[bi] }, toTiffFile);

            //                fileImageFullPathes.Add(string.Format("{0}|{1}", absolute_folder_path, file_name));
            //                generatedImages[generatedImagesKey] = fileImageFullPathes;
            //                #endregion
            //            }
            //        }




            //        /*
            //         * after separation I generate tiff file and then add it to the main list to be generated in the XML file
            //         */

            //        foreach (KeyValuePair<string, List<DAL.GarafatDatabase.INFC_PAGE>> stabledImages in generatedStabledImages)
            //        {

            //            //get the Images files list
            //            List<DAL.GarafatDatabase.INFC_PAGE> stabledFileImages = stabledImages.Value;

            //            //nodes indexes
            //            barcode_value = string.Empty;
            //            main_category_name = (string.IsNullOrEmpty(stabledFileImages[0].PAGE_FLD01_VAL)) ? string.Empty : stabledFileImages[0].PAGE_FLD01_VAL;
            //            sub_category_code = "00";
            //            sub_category_name = (string.IsNullOrEmpty(stabledFileImages[0].PAGE_FLD05_VAL)) ? string.Empty : stabledFileImages[0].PAGE_FLD05_VAL;
            //            document_type_code = "00";
            //            document_type_name = (string.IsNullOrEmpty(stabledFileImages[0].PAGE_FLD06_VAL)) ? string.Empty : stabledFileImages[0].PAGE_FLD06_VAL;

            //            //absolute_folder_path = Path.Combine("W" + weekNumber.ToString(), employee_id, main_category_name.Split('.').ToList()[0]);
            //            absolute_folder_path = Path.Combine("W" + weekNumber.ToString(), employee_id, main_category_name.Split('.').ToList()[0], sub_category_name.Split('.').ToList()[0], document_type_name.Split('.').ToList()[0]);

            //            string full_folder_path = Path.Combine(currentExportingFolder, absolute_folder_path);

            //            string generatedImagesKey = string.Format("{0}*{1}*{2}", main_category_name, sub_category_name, document_type_name);

            //            if (!generatedImages.ContainsKey(generatedImagesKey))
            //            {
            //                generatedImages.Add(generatedImagesKey, new List<string>());
            //            }

            //            List<string> fileImageFullPathes = generatedImages[generatedImagesKey];

            //            DirectoryInfo dirFull_folder_path = new DirectoryInfo(full_folder_path);
            //            dirFull_folder_path.Create();

            //            //int newFileCount = createdImagesNames[full_folder_path].Count + 1;//------------------->dirFull_folder_path.GetFiles("*.tiff").Count() + 1;
            //            int newFileCount = 0;

            //            try { newFileCount = (createdImagesNames[full_folder_path].Count + 1); }
            //            catch
            //            {
            //                newFileCount = 1;
            //            }
            //            #region add temp names
            //            //add temp names
            //            if (!createdImagesNames.ContainsKey(full_folder_path))
            //            {
            //                createdImagesNames.Add(full_folder_path, new List<string>());
            //            }

            //            List<string> tempImagesNames = createdImagesNames[full_folder_path];
            //            tempImagesNames.Add((newFileCount).ToString());
            //            createdImagesNames[full_folder_path] = tempImagesNames;
            //            #endregion

            //            //string newTiffFileName = string.Format("{0}.txt", newFileCount.ToString("000000"));
            //            string newTiffFileName = string.Format("{0}.tiff", newFileCount.ToString("000000"));
            //            file_name = string.Format("{0}.pdf_{1}", newFileCount.ToString("000000"), stabledFileImages.Count.ToString());

            //            //copy the tiff file to be then converted to pdf
            //            //new FileInfo(Path.Combine(full_folder_path, newTiffFileName)).Create();

            //            fileImageFullPathes.Add(string.Format("{0}|{1}", absolute_folder_path, file_name));
            //            generatedImages[generatedImagesKey] = fileImageFullPathes;

            //            if (exportImages)
            //            {
            //                //create the multitiff files
            //                GENERATE_MULTITIFF_FILE(stabledFileImages, Path.Combine(full_folder_path, newTiffFileName));
            //            }


            //        }

            //        #region Check Export XML

            //        decimal employeeImagesCount = 0;
            //        if (exportXml)
            //        {

            //            foreach (KeyValuePair<string, List<string>> generated_document_type in generatedImages)
            //            {
            //                List<string> currentSelectedKeys = generated_document_type.Key.Split('*').ToList();

            //                main_category_code = currentSelectedKeys[0].Split('.')[0];
            //                sub_category_code = (string.IsNullOrEmpty(currentSelectedKeys[1])) ? "00" : currentSelectedKeys[1].Split('.')[0];
            //                document_type_code = (string.IsNullOrEmpty(currentSelectedKeys[2])) ? "00" : currentSelectedKeys[2].Split('.')[0];

            //                main_category_name = currentSelectedKeys[0].Split('.')[1];
            //                sub_category_name = (string.IsNullOrEmpty(currentSelectedKeys[1])) ? "" : currentSelectedKeys[1].Split('.')[1];
            //                document_type_name = (string.IsNullOrEmpty(currentSelectedKeys[2])) ? "" : currentSelectedKeys[2].Split('.')[1];

            //                List<string> fileImageFullPathes = generated_document_type.Value;

            //                employeeImagesCount += fileImageFullPathes.Count;

            //                for (int pgs = 0; pgs < fileImageFullPathes.Count; pgs++)
            //                {
            //                    //Document
            //                    XmlElement xmlDocumentElement = _xmlDoc.CreateElement(String.Empty, "Document", String.Empty);
            //                    xmlSubElement.AppendChild(xmlDocumentElement);

            //                    {
            //                        //barcode_value
            //                        barcode_value = string.Empty;
            //                        XmlElement xmlDocumentTypeElement = _xmlDoc.CreateElement(String.Empty, "barcode_value", String.Empty);
            //                        XmlText xmlDocumentTypeText = _xmlDoc.CreateTextNode(barcode_value);
            //                        xmlDocumentTypeElement.AppendChild(xmlDocumentTypeText);
            //                        xmlDocumentElement.AppendChild(xmlDocumentTypeElement);

            //                        //main_category_code
            //                        //-------------->main_category_code = generated_document_type.Key.Split('.').ToList()[0];
            //                        xmlDocumentTypeElement = _xmlDoc.CreateElement(String.Empty, "main_category_code", String.Empty);
            //                        xmlDocumentTypeText = _xmlDoc.CreateTextNode(main_category_code);
            //                        xmlDocumentTypeElement.AppendChild(xmlDocumentTypeText);
            //                        xmlDocumentElement.AppendChild(xmlDocumentTypeElement);

            //                        //main_category_name
            //                        //------------->main_category_name = string.Empty;//-------------------> generated_document_type.Key.Split('.').ToList()[1];
            //                        xmlDocumentTypeElement = _xmlDoc.CreateElement(String.Empty, "main_category_name", String.Empty);
            //                        xmlDocumentTypeText = _xmlDoc.CreateTextNode(main_category_name);
            //                        xmlDocumentTypeElement.AppendChild(xmlDocumentTypeText);
            //                        xmlDocumentElement.AppendChild(xmlDocumentTypeElement);

            //                        //sub_category_code
            //                        //------------->sub_category_code = "00";
            //                        xmlDocumentTypeElement = _xmlDoc.CreateElement(String.Empty, "sub_category_code", String.Empty);
            //                        xmlDocumentTypeText = _xmlDoc.CreateTextNode(sub_category_code);
            //                        xmlDocumentTypeElement.AppendChild(xmlDocumentTypeText);
            //                        xmlDocumentElement.AppendChild(xmlDocumentTypeElement);

            //                        //sub_category_name
            //                        //------------->sub_category_name = string.Empty;
            //                        xmlDocumentTypeElement = _xmlDoc.CreateElement(String.Empty, "sub_category_name", String.Empty);
            //                        xmlDocumentTypeText = _xmlDoc.CreateTextNode(sub_category_name);
            //                        xmlDocumentTypeElement.AppendChild(xmlDocumentTypeText);
            //                        xmlDocumentElement.AppendChild(xmlDocumentTypeElement);

            //                        //document_type_code
            //                        //-------------->document_type_code = "00";
            //                        xmlDocumentTypeElement = _xmlDoc.CreateElement(String.Empty, "document_type_code", String.Empty);
            //                        xmlDocumentTypeText = _xmlDoc.CreateTextNode(document_type_code);
            //                        xmlDocumentTypeElement.AppendChild(xmlDocumentTypeText);
            //                        xmlDocumentElement.AppendChild(xmlDocumentTypeElement);

            //                        //document_type_name
            //                        //------------->document_type_name = string.Empty;
            //                        xmlDocumentTypeElement = _xmlDoc.CreateElement(String.Empty, "document_type_name", String.Empty);
            //                        xmlDocumentTypeText = _xmlDoc.CreateTextNode(document_type_name);
            //                        xmlDocumentTypeElement.AppendChild(xmlDocumentTypeText);
            //                        xmlDocumentElement.AppendChild(xmlDocumentTypeElement);


            //                        {
            //                            file_name = fileImageFullPathes[pgs].Split('|')[1];

            //                            //number_of_pages
            //                            number_of_pages = file_name.Split('_').ToList()[1];
            //                            xmlDocumentTypeElement = _xmlDoc.CreateElement(String.Empty, "number_of_pages", String.Empty);
            //                            xmlDocumentTypeText = _xmlDoc.CreateTextNode(number_of_pages);
            //                            xmlDocumentTypeElement.AppendChild(xmlDocumentTypeText);
            //                            xmlDocumentElement.AppendChild(xmlDocumentTypeElement);

            //                            //absolute_folder_path
            //                            absolute_folder_path = (!sub_category_code.Equals("00")) ? Path.Combine(main_category_code, sub_category_code, document_type_code) : main_category_code;// fileImageFullPathes[0].Split('|')[0];
            //                            xmlDocumentTypeElement = _xmlDoc.CreateElement(String.Empty, "absolute_folder_path", String.Empty);
            //                            xmlDocumentTypeText = _xmlDoc.CreateTextNode(absolute_folder_path); //(@"\" + absolute_folder_path);
            //                            xmlDocumentTypeElement.AppendChild(xmlDocumentTypeText);
            //                            xmlDocumentElement.AppendChild(xmlDocumentTypeElement);

            //                            //file_name
            //                            file_name = file_name.Split('_').ToList()[0];
            //                            xmlDocumentTypeElement = _xmlDoc.CreateElement(String.Empty, "file_name", String.Empty);
            //                            xmlDocumentTypeText = _xmlDoc.CreateTextNode(file_name);
            //                            xmlDocumentTypeElement.AppendChild(xmlDocumentTypeText);
            //                            xmlDocumentElement.AppendChild(xmlDocumentTypeElement);
            //                        }
            //                    }
            //                }
            //            }
            //        }
            //        #endregion

            //        #endregion

            //        fileName = employee_id;

            //        ExportedEmployeesReport.Add(string.Format("{0}#{1}", fileName, employeeImagesCount.ToString()));
            //    }

            //}
            #endregion

            #region 4. Save The XML
            try
            {
                string fullSavingNameXML = string.Format(@"{0}\\{1}.xml", xML_EXPORTING_PATH, aRCHIVE_DEPARTMENT_FILE.ARCHIVE_DEPARTMENT_FILE_ID.ToString());

                new FileInfo(fullSavingNameXML).Delete();

                _xmlDoc.Save(fullSavingNameXML);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            #endregion
        }
    }
}
